package com.oplink.webems.modules.cfg.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.oplink.webems.modules.sys.utils.inf.IDict;

/**
 * Configuration Site Entity
 * 
 * @author yizhang
 */
@Entity
@Table(name = "cfg_site")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CfgSite implements IDict {

	// ID
	private Long sid;

	// 站点名称
	private String sname;

	// 是否禁用
	private String enable;

	@JSONField(serialize=false)
	List<CfgNe> nelist = Lists.newArrayList();

	public String getEnable() {
		return enable;
	}

	public void setEnable(String enable) {
		this.enable = enable;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getSid() {
		return sid;
	}

	public void setSid(Long sid) {
		this.sid = sid;
	}

	public String getSname() {
		return sname;
	}

	public void setSname(String sname) {
		this.sname = sname;
	}

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "site")
	@NotFound(action = NotFoundAction.IGNORE)
	//@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@JsonIgnore
	public List<CfgNe> getNelist() {
		return nelist;
	}

	public void setNelist(List<CfgNe> nelist) {
		this.nelist = nelist;
	}

	public void setLabel(String label) {
	}

	public void setValue(String value) {
	}

	@Transient
	@Override
	public String getLabel() {
		return sname;
	}

	@Transient
	@Override
	public String getValue() {
		return sid.toString();
	}
}
